# stats script
# requires config.stats to be defined

import config
irc = None

def init(bot):
    global irc
    bot.cmd.events['PRIVMSG'].subscribe(privmsg)
    bot.cmd.events['NOTICE'].subscribe(notice)
    bot.cmd.events['KICK'].subscribe(kick)
    irc = bot
    
def notice(sender, args):
    global irc
    if args[0] == "get lost":
        irc.quit("quit command recieved from %s" % sender.nick)
        pass

def kick(sender, args):
    global irc
    print config.stats
    #print args
    # ('SOME MESSAGE', 'KICK', '#boofbot', 'tom____')
    nick = args[3]
    try:
        config.stats[nick] += 1
    except KeyError:
        config.stats[nick] = 1
    print "someone got kicked: %s" % args[3]



def privmsg(sender, args):
    global irc
    global stats
    msg = args[0].split()

    if msg:
        if msg[0] == "!kickstat":
            irc.privmsg(args[2], config.stats)
        if msg[0] == "!kstat":
                try: name = msg[1]
                except: name = ""
                try: kicks = config.stats[name]
                except KeyError: kicks = 0
                irc.privmsg(args[2], "%s: %i" % (name, kicks))
    if args[0] == "get lost":
        if irc.chmgr.get(args[2]).isop(sender.nick):
            irc.terminate("you're the boss")
            pass
